import {getProduct,getTProduct,getUContates} from '../../api/orderdetails'

Page({
  data: {
    orderInfo: {
      status: 0,
      goodsImg: 'https://via.placeholder.com/120', // 实际替换商品图链接
      goodsTitle: '复古蓝色格纹花苞半身裙女大码',
      goodsSpec: '蓝色[【内带安全裤】];L',
      goodsCount: 1,
      goodsPrice: 39.9,
      actualPayment: 39.9,
      otherInfos: [
        { label: '订单编号', value: '2831845477441419797' },
        { label: '创建时间', value: '2025-07-16 11:29:58' },
        { label: '付款时间', value: '2025-07-16 11:30:05' },
        { label: '游玩时间', value: '2025-07-17 23:23:15' },
    
      ],
      
    },
    contatesList:[]
  },

  async getOrderInfo(pType,pid){
    if(pType==0){
      const list=this.data.orderInfo
      const data=await getProduct(pid)
      console.log(data)
      list.pname=data.data.product.productName
      this.setData({
        orderInfo:list
      })
      console.log(this.data.orderInfo)
    }else{
      const list=this.data.orderInfo
      const data=await getTProduct(pid)
      console.log(data)
      list.pname=data.data.product.name
      const date1 = new Date(list.createTime); // 解析为 Date 对象
      const date2 = new Date(list.updateTime); // 解析为 Date 对象
      list.createTime = date1.toISOString().replace("T", " ").slice(0, 19); 
      list.updateTime = date2.toISOString().replace("T", " ").slice(0, 19); 
      this.setData({
        orderInfo:list
      })
      console.log(this.data.orderInfo)
    }
    let contates=await getUContates(this.data.orderInfo.contactsId)
    console.log(contates)
    contates.data.list.forEach(element => {
      element.idcard=element.idcard.substring(0,4)+"************"+element.idcard.substring(14)
    });
    this.setData({
      contatesList:contates.data.list
    })
    console.log(this.data.contatesList)
  },

  onLoad(options){
    const obj = JSON.parse(options.orderInfo); // 还原为对象
    console.log(obj)
    this.setData({
      orderInfo:obj
    })
    this.getOrderInfo(this.data.orderInfo.detailInfo[0].productType,this.data.orderInfo.detailInfo[0].productId)
  },

  onIdleFishTap() {
    // 闲鱼转卖逻辑，可跳转对应页面或调用接口
    wx.showToast({ title: '前往闲鱼转卖', icon: 'none' });
  },
  onAfterSaleTap() {
    // 申请售后逻辑
    wx.showToast({ title: '申请售后流程', icon: 'none' });
  },
  onAddCartTap() {
    // 加入购物车逻辑，调用接口添加商品
    wx.showToast({ title: '加入购物车成功', icon: 'success' });
  }
})